from os import walk
import pygame

"""
导入文件的工具函数
"""
def import_folder(path):
	surface_list = []
	'''
	用于遍历文件夹和子文件夹的函数
	它返回一个生成器，可以用于循环遍历指定路径下的所有文件夹、子文件夹和文件
	folder_name: 当前文件夹的路径
	sub_folder: 当前文件夹中的子文件夹列表
	img_files: 当前文件夹中的文件列表
	'''
	for folder_name, sub_folder, img_files in walk(path):
		for image in img_files:
			full_path = path + '/' + image
			# 加载图片
			image_surf = pygame.image.load(full_path).convert_alpha()
			surface_list.append(image_surf)

	return surface_list


def import_folder_dict(path):
	surface_dict = {}
	for _, __, img_files in walk(path):
		for image in img_files:
			full_path = path + '/' + image
			image_surf = pygame.image.load(full_path).convert_alpha()
			surface_dict[image.split('.')[0]] = image_surf

	return surface_dict
